mylist = ["itcast", "itheima", "python", "hello"]


# 注意列表下标从0开始计数
# 若列表中无查找的字符串，会报错
index = mylist.index("itheima")
print(f"itheima在列表中的下标索引值是：{index}")
index = mylist.index("hello")
print(f"hello在列表中的下标索引值是：{index}")

# 修改功能
mylist[0] = "传智教育"
print(f"修改后：{mylist}")

# 在指定位置插入元素
mylist.insert(1, "best")
print(f"列表插入元素后为：{mylist}")

# 追加元素1
mylist.append(123)
print(f"在尾部操作1后：{mylist}")

# 追加元素2
mylist2 = [4, 5, 6]
mylist.extend(mylist2)
print(f"在尾部操作2后：{mylist}")

# 元素删除
mylist = ["itcast", "itheima", "python", "hello"]
del mylist[2]
print(f"删除后：{mylist}")

element = mylist.pop(0)
print(f"通过pop方法删除，删除后：{mylist},删除的元素是：{element}")

# 删除匹配项
mylist = ["itcast", "itheima", "python", "hello", "itheima"]
mylist.remove("itheima")  # 从左向右只删一次

print(f"删除后：{mylist}")

# 清空列表
mylist.clear()
print(f"清空后：{mylist}")

# 统计某元素数量
mylist = ["itcast", "itheima", "python", "hello", "itheima"]
count = mylist.count("itheima")
print(f"\"itheima\"数量有{count}个")

# 列表总共有多少元素
count1 = len(mylist)
print(f"列表总共有{count1}元素")
